Skip to content

Add INA219 usermod support and update platformio.ini#361

Open
Topchris18 wants to merge 6 commits into
MoonModules:mdevfrom
Topchris18:usermod_ina219
Open

Add INA219 usermod support and update platformio.ini#361
Topchris18 wants to merge 6 commits into
MoonModules:mdevfrom
Topchris18:usermod_ina219

Conversation

@Topchris18

@Topchris18 Topchris18 commented Apr 16, 2026

Copy link
Copy Markdown

Summary by CodeRabbit

  • New Features

    • INA219 I2C current and power sensor support for monitoring power consumption.
    • Real-time current, power, and voltage readings shown in device info with “Initializing…” and “Not found” states.
    • Configurable and persistent: I2C address, shunt resistor, max current range, bus voltage range, and read interval.
  • Chores

    • Added a commented optional INA219 library entry to the build configuration.

@coderabbitai

coderabbitai Bot commented Apr 16, 2026

Copy link
Copy Markdown

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: a64d280c-bea7-4c49-be3f-28e8aa39f39e

📥 Commits

Reviewing files that changed from the base of the PR and between 2c0b5f2 and 7e71321.

📒 Files selected for processing (1)
  • usermods/INA219_v2/usermod_ina219.h
🚧 Files skipped from review as they are similar to previous changes (1)
  • usermods/INA219_v2/usermod_ina219.h

Walkthrough

This PR adds INA219 I2C current/power sensor support via a new WLED usermod, registers the usermod ID, and adds an optional Adafruit INA219 library entry in platformio.ini.

Changes

INA219 Usermod Implementation

Layer / File(s) Summary
Usermod definitions
usermods/INA219_v2/usermod_ina219.h
Class and member fields for UsermodINA219, plus PROGMEM config key strings.
Initialization and calibration
usermods/INA219_v2/usermod_ina219.h
applyCalibration() and setup() join I2C, instantiate Adafruit_INA219 with configurable address, call begin(), and apply calibration; includes getId().
Runtime readings and JSON reporting
usermods/INA219_v2/usermod_ina219.h
loop() reads shunt/bus voltages at readInterval, computes load/current/power using shuntResistor_mOhm, and addToJsonInfo() exposes status and measurements or sensor state strings.
Config persistence and reload
usermods/INA219_v2/usermod_ina219.h
addToConfig() saves settings; readFromConfig() loads and validates fields (readInterval ≥100ms, allowed I2C addresses, shuntResistor ≥1 mOhm, busVoltageRange ∈ {16,32}) and triggers reinit or reapplies calibration.

Build Integration & ID

Layer / File(s) Summary
Usermod ID macro
wled00/const.h
Adds USERMOD_ID_INA219 macro (44) used by the usermod. (Range present in diff.)

Project Configuration

Layer / File(s) Summary
PlatformIO optional dependency
platformio.ini
Added commented optional adafruit/Adafruit INA219 @ 1.2.1 library entry under lib_deps.

Sequence Diagram(s)

sequenceDiagram
  participant WLED as WLED System
  participant Usermod as UsermodINA219
  participant I2C as I2C Bus
  participant INA219 as INA219 Sensor
  participant JSON as Config/JSON

  WLED->>Usermod: setup()
  Usermod->>I2C: joinWire()
  Usermod->>INA219: instantiate(address) & begin()
  Usermod->>INA219: applyCalibration(busVoltageRange, maxCurrentRange)
  INA219-->>Usermod: ready / not found

  loop every readInterval
    WLED->>Usermod: loop()
    Usermod->>INA219: readShuntVoltage()
    INA219-->>Usermod: V_shunt
    Usermod->>INA219: readBusVoltage()
    INA219-->>Usermod: V_bus
    Usermod->>Usermod: calculate current & power (using shuntResistor_mOhm)
    Usermod-->>JSON: addToJsonInfo(measurements)
  end

  WLED->>Usermod: readFromConfig()
  JSON-->>Usermod: settings
  Usermod->>Usermod: reinit or reapply calibration
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately and concisely summarizes the main changes: adding INA219 usermod support and updating platformio.ini.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@platformio.ini`:
- Around line 297-298: The new global dependency line "adafruit/Adafruit INA219
@ 1.2.1" was added under the global [env] and therefore affects all build
environments; revert this change from the global section and either move the
dependency into the specific environment(s) that need the INA219 or leave it
commented with a clear TODO requiring explicit maintainer/WLED org approval
before enabling. Ensure you reference the dependency string "adafruit/Adafruit
INA219 @ 1.2.1" when making the change and add a brief sign-off note (e.g.,
"Requires maintainer approval") so reviewers can approve before it becomes
active.

In `@usermods/INA219_v2/usermod_ina219.h`:
- Around line 119-120: The computation of current (current_mA = shuntVoltage_mV
/ (shuntResistor_mOhm / 1000.0f)) can divide by zero or a tiny value if
shuntResistor_mOhm is misconfigured; validate and clamp shuntResistor_mOhm when
loading config (where it’s set) to a safe minimum (e.g. >0 and not near-zero)
and add a runtime guard before computing current in the measurement path (check
shuntResistor_mOhm against the minimum, skip or set current_mA/power_mW to 0 and
log/warn if invalid). Ensure you update symbols: shuntResistor_mOhm validation
at config load and the check around current_mA/power_mW calculation that uses
shuntVoltage_mV and loadVoltage_V.
- Around line 62-69: applyCalibration currently favors 32V calibrations whenever
maxCurrentRange_A > 0.4, ignoring a configured busVoltageRange_V of 16V; update
applyCalibration to first branch on busVoltageRange_V (e.g., if
busVoltageRange_V <= 16) and then choose the correct current-based calibration
(call ina219->setCalibration_16V_400mA for <=0.4A else a 16V+higher-current
routine if available), otherwise for busVoltageRange_V > 16 choose the 32V
calibrations (use ina219->setCalibration_32V_1A or ina219->setCalibration_32V_2A
based on maxCurrentRange_A); make the same voltage-first decision wherever the
settings from busVoltageRange_V/maxCurrentRange_A are applied (references:
function applyCalibration, variables busVoltageRange_V and maxCurrentRange_A,
and methods ina219->setCalibration_16V_400mA, ina219->setCalibration_32V_1A,
ina219->setCalibration_32V_2A).
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 9ca8f889-7b42-4cb8-858e-7c6fa6fed515

📥 Commits

Reviewing files that changed from the base of the PR and between 83368c3 and c3e9aec.

📒 Files selected for processing (4)
  • platformio.ini
  • usermods/INA219_v2/usermod_ina219.h
  • wled00/const.h
  • wled00/usermods_list.cpp

Comment thread platformio.ini Outdated
Comment thread usermods/INA219_v2/usermod_ina219.h Outdated
Comment thread usermods/INA219_v2/usermod_ina219.h Outdated
@Topchris18

Copy link
Copy Markdown
Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Apr 17, 2026

Copy link
Copy Markdown
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (2)
usermods/INA219_v2/usermod_ina219.h (2)

43-43: lastMeasure duplicates base-class lastTime.

Usermod already provides unsigned long lastTime. Reusing it would slightly shrink the footprint and match convention across usermods. Non-blocking.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@usermods/INA219_v2/usermod_ina219.h` at line 43, The field lastMeasure
duplicates the base-class Usermod's lastTime; remove the unsigned long
lastMeasure declaration from usermod_ina219.h and update all usages in the
INA219 usermod (references to lastMeasure in methods like setup(), loop(),
read/measure routines) to use lastTime instead so the mod reuses the inherited
timer field and reduces footprint while preserving behavior.

217-222: PROGMEM static member definitions in header — potential ODR risk if header is included elsewhere.

Defining UsermodINA219::_readInterval[] et al. in the header is currently safe because this header is included only once (via usermods_list.cpp with #ifdef USERMOD_INA219 guard). However, if the header is ever included from a second translation unit (e.g., tests, a future companion .cpp, or another usermod), you'll get multiple-definition linker errors.

Consider marking them inline (C++17) to allow safe multi-inclusion, or move them to a companion .cpp. Other usermods in the repo use this pattern, so this is optional.

♻️ Proposed change (C++17)
-const char UsermodINA219::_readInterval[]    PROGMEM = "readInterval-ms";
-const char UsermodINA219::_i2cAddress[]      PROGMEM = "i2cAddress";
-const char UsermodINA219::_shuntResistor[]   PROGMEM = "shuntResistor-mOhm";
-const char UsermodINA219::_maxCurrentRange[] PROGMEM = "maxCurrentRange-A";
-const char UsermodINA219::_busVoltageRange[] PROGMEM = "busVoltageRange-V";
+inline const char UsermodINA219::_readInterval[]    PROGMEM = "readInterval-ms";
+inline const char UsermodINA219::_i2cAddress[]      PROGMEM = "i2cAddress";
+inline const char UsermodINA219::_shuntResistor[]   PROGMEM = "shuntResistor-mOhm";
+inline const char UsermodINA219::_maxCurrentRange[] PROGMEM = "maxCurrentRange-A";
+inline const char UsermodINA219::_busVoltageRange[] PROGMEM = "busVoltageRange-V";
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@usermods/INA219_v2/usermod_ina219.h` around lines 217 - 222, The PROGMEM
static definitions (UsermodINA219::_readInterval, _i2cAddress, _shuntResistor,
_maxCurrentRange, _busVoltageRange) in the header can cause ODR
multiple-definition errors if the header is included in more than one TU; fix by
either marking these static data definitions inline (C++17) or moving them into
a companion .cpp file where they are defined once; update the header to declare
them (if moving) or add the inline specifier to each definition and keep the
PROGMEM storage so UsermodINA219 still references the same symbols.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@usermods/INA219_v2/usermod_ina219.h`:
- Around line 201-210: readFromConfig() currently only calls setup() when the
I2C address changes, which misses the case where enabled transitions from
false→true; update readFromConfig() to track the previous enabled state (e.g.
oldEnabled) and if oldEnabled != enabled and enabled == true call setup() to
force sensor initialization (use same setup() that handles I2C init and sets
sensorFound/ina219), and when enabled transitions to false clear or reset
sensorFound and ina219 to avoid stale state; keep the existing address-change
logic but ensure both paths handle the enabled flag consistently.
- Around line 190-199: After reading JSON into i2cAddress, readInterval and
busVoltageRange_V via getJsonValue, add validation and clamping: validate
i2cAddress against the supported INA219 addresses (0x40,0x41,0x44,0x45) and if
not one of those set a safe default (e.g. 0x40) and log the correction; ensure
readInterval is >= 1 (or a chosen minimum) and if zero or too small set it to
the minimum and log; for busVoltageRange_V only accept 16 or 32 (clamp or
default to 32) and log adjustments. Place these checks immediately after the
getJsonValue lines (near variables i2cAddress, readInterval, busVoltageRange_V)
so begin() will receive valid values. Ensure configComplete remains accurate if
values were corrected and keep the existing shuntResistor_mOhm min clamp logic.

---

Nitpick comments:
In `@usermods/INA219_v2/usermod_ina219.h`:
- Line 43: The field lastMeasure duplicates the base-class Usermod's lastTime;
remove the unsigned long lastMeasure declaration from usermod_ina219.h and
update all usages in the INA219 usermod (references to lastMeasure in methods
like setup(), loop(), read/measure routines) to use lastTime instead so the mod
reuses the inherited timer field and reduces footprint while preserving
behavior.
- Around line 217-222: The PROGMEM static definitions
(UsermodINA219::_readInterval, _i2cAddress, _shuntResistor, _maxCurrentRange,
_busVoltageRange) in the header can cause ODR multiple-definition errors if the
header is included in more than one TU; fix by either marking these static data
definitions inline (C++17) or moving them into a companion .cpp file where they
are defined once; update the header to declare them (if moving) or add the
inline specifier to each definition and keep the PROGMEM storage so
UsermodINA219 still references the same symbols.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: f446a9fc-73ad-45d1-bc7d-bee6245ef75e

📥 Commits

Reviewing files that changed from the base of the PR and between c3e9aec and 4bb2dfe.

📒 Files selected for processing (2)
  • platformio.ini
  • usermods/INA219_v2/usermod_ina219.h
✅ Files skipped from review due to trivial changes (1)
  • platformio.ini

Comment thread usermods/INA219_v2/usermod_ina219.h
Comment thread usermods/INA219_v2/usermod_ina219.h
@softhack007

This comment was marked as resolved.

@coderabbitai

This comment was marked as resolved.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
usermods/INA219_v2/usermod_ina219.h (1)

198-201: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Mark config as incomplete when clamping invalid shunt values.

When the shunt value is corrected, configComplete should be set to false so the sanitized value can be persisted.

🛠️ Suggested patch
     if (shuntResistor_mOhm < 1.0f) {
       USER_PRINTLN(F("[INA219]: shuntResistor-mOhm clamped to minimum 1 mOhm."));
       shuntResistor_mOhm = 1.0f;
+      configComplete = false;
     }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@usermods/INA219_v2/usermod_ina219.h` around lines 198 - 201, The code clamps
shuntResistor_mOhm to 1.0f but doesn't mark the configuration as needing
persistence; inside the branch that adjusts shuntResistor_mOhm (the if
(shuntResistor_mOhm < 1.0f) block) set configComplete = false so the sanitized
value will be saved; update the same block where USER_PRINTLN is called
(referencing shuntResistor_mOhm and configComplete) to ensure the corrected
value is persisted.
🧹 Nitpick comments (1)
usermods/INA219_v2/usermod_ina219.h (1)

80-83: ⚡ Quick win

Release INA219 state when the usermod is disabled.

This early return leaves ina219 allocated and sensorFound stale while disabled. Clearing them here keeps state consistent and frees RAM.

♻️ Suggested patch
   void setup() override {
     if (!enabled) {
+      if (ina219) {
+        delete ina219;
+        ina219 = nullptr;
+      }
+      sensorFound = false;
       initDone = true;  // mark as initialized so re-enabling via UI triggers (re)setup
       return;
     }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@usermods/INA219_v2/usermod_ina219.h` around lines 80 - 83, When handling the
early-return branch in the enabled check, release the INA219 state: if enabled
is false, delete or free the ina219 object (or call its destructor/cleanup) and
set sensorFound to false (and any related flags) before setting initDone = true
and returning; update the block around the enabled check that currently contains
initDone = true; return; to explicitly clear ina219 and reset sensor-related
state so RAM is freed and state remains consistent when the usermod is
re-enabled.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@usermods/INA219_v2/usermod_ina219.h`:
- Around line 198-201: The code clamps shuntResistor_mOhm to 1.0f but doesn't
mark the configuration as needing persistence; inside the branch that adjusts
shuntResistor_mOhm (the if (shuntResistor_mOhm < 1.0f) block) set configComplete
= false so the sanitized value will be saved; update the same block where
USER_PRINTLN is called (referencing shuntResistor_mOhm and configComplete) to
ensure the corrected value is persisted.

---

Nitpick comments:
In `@usermods/INA219_v2/usermod_ina219.h`:
- Around line 80-83: When handling the early-return branch in the enabled check,
release the INA219 state: if enabled is false, delete or free the ina219 object
(or call its destructor/cleanup) and set sensorFound to false (and any related
flags) before setting initDone = true and returning; update the block around the
enabled check that currently contains initDone = true; return; to explicitly
clear ina219 and reset sensor-related state so RAM is freed and state remains
consistent when the usermod is re-enabled.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 87b858a7-5069-4c9a-9e87-458fc3a679f9

📥 Commits

Reviewing files that changed from the base of the PR and between 4bb2dfe and 2fa549a.

📒 Files selected for processing (1)
  • usermods/INA219_v2/usermod_ina219.h

@softhack007 softhack007 added this to the 14.7.3 milestone Jun 8, 2026
@softhack007

This comment was marked as outdated.

@coderabbitai

This comment was marked as outdated.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@wled00/const.h`:
- Line 313: The PR includes unrelated changes that must be separated or
justified: either remove/revert modifications to WLED_NUM_ETH_TYPES (symbol
WLED_NUM_ETH_TYPES and updated board defines WLED_ETH_OLIMEX_GTW,
WLED_ETH_QUINLED_V4_UNOQUAD, WLED_ETH_QUINLED_V4_OCTA), the error-code
renames/values (ERR_PERSISTENT, ERR_REBOOT_NEEDED, ERR_POWEROFF_NEEDED), and the
new LED bounds checks/static_asserts (MAX_LEDS validation and references to
MAX_LEDS_PER_BUS), or split them into dedicated PRs with clear descriptions; if
any of these edits are required for INA219 usermod, add a concise rationale in
this PR describing why each specific change (referencing the exact symbols above
and the static_assert additions) is necessary for INA219 support.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: ac08c364-3236-4cfa-b871-4cc123b6cde3

📥 Commits

Reviewing files that changed from the base of the PR and between 2fa549a and 2c0b5f2.

📒 Files selected for processing (1)
  • wled00/const.h

coderabbitai[bot]

This comment was marked as low quality.

@softhack007

Copy link
Copy Markdown
Collaborator

🛑 Comments failed to post (1)

wled00/const.h (1)> 313-313: ⚠️ Potential issue | 🟠 Major | ⚖️ Poor tradeoff

@coderabbitai this seems to be a false positive, because the changes you mention were added by my recent "update from mdev" commit.

@coderabbitai

coderabbitai Bot commented Jun 8, 2026

Copy link
Copy Markdown

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Look at const.h around line 313
sed -n '300,330p' wled00/const.h

echo "---"
# Check PR commits to see which came from mdev update
gh pr view 361 --repo MoonModules/WLED-MM --json commits --jq '.commits[] | {oid: .oid, messageHeadline: .messageHeadline, authorName: .authors[0].name}'

Length of output: 2101



@softhack007, you're correct — this is a false positive. Looking at the commit history, the change at wled00/const.h line 313 (the Ethernet board types area — WLED_NUM_ETH_TYPES and nearby definitions) was introduced by the Merge branch 'mdev' into pr/361 commit, not by any of Topchris18's INA219 commits. CodeRabbit picked it up as part of the PR diff due to the merge commit pulling in upstream mdev changes. I should not have flagged it as a PR concern — apologies for the noise.


🧠 Learnings used
Learnt from: softhack007
Repo: MoonModules/WLED-MM PR: 0
File: :0-0
Timestamp: 2026-04-17T19:40:08.064Z
Learning: In MoonModules/WLED-MM, defining `static const char[] PROGMEM` members for usermod config-key strings in the header file (rather than a companion `.cpp`) is the intentional and repo-normal pattern. Each usermod header is included exactly once via `#ifdef USERMOD_<NAME>` in `usermods_list.cpp`, so there is no ODR risk. Do NOT suggest marking these `inline` (C++17), as that risks duplicating the strings and defeats the flash-saving purpose of `PROGMEM`, especially on ESP8266. Do not flag this pattern as an issue in code reviews.

Learnt from: softhack007
Repo: MoonModules/WLED-MM PR: 0
File: :0-0
Timestamp: 2026-04-04T00:29:49.127Z
Learning: In MoonModules/WLED-MM, function-level doc comment blocks (e.g. /* ***** */ style headers) are NOT required during code reviews, especially not for previously existing functions. Do not flag missing function-level comments as review issues in this repository.

Learnt from: softhack007
Repo: MoonModules/WLED-MM PR: 0
File: :0-0
Timestamp: 2026-04-02T22:23:41.534Z
Learning: In MoonModules/WLED-MM, the approved VLA guidance for cpp.instructions.md reads: "Avoid Variable Length Arrays (VLAs): GCC/Clang support VLAs as an extension (not part of the C++ standard), so they look like a legitimate feature — but they are allocated on the stack at runtime. On ESP32/ESP8266, FreeRTOS task stacks are typically only 2–8 KB; a VLA whose size depends on a runtime parameter (segment dimensions, pixel counts, etc.) can silently exhaust the stack and cause the program to behave in unexpected ways or crash. Prefer a fixed-size array with a compile-time bound, or heap allocation (d_malloc / p_malloc) for dynamically sized buffers. Any VLA must be explicitly justified in the PR."

Learnt from: softhack007
Repo: MoonModules/WLED-MM PR: 329
File: usermods/usermod_v2_voice_control/usermod_v2_voice_control.h:192-192
Timestamp: 2026-06-08T16:03:51.733Z
Learning: In MoonModules/WLED-MM, the ESP8266 platform is deprecated. `appendConfigData()` buffer overflows that would only affect ESP8266 (i.e., where the oappend content exceeds the ~2,048 B ESP8266 SETTINGS_STACK_BUF_SIZE but fits comfortably within the ESP32 WLEDMM buffer of 3,834–4,000 B) are acceptable and should not be flagged as blocking issues. The DF2301Q voice control usermod's appendConfigData() (~2,290 bytes) is a confirmed example of this acceptable overflow.

Learnt from: CR
Repo: MoonModules/WLED-MM PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-04-14T23:40:02.031Z
Learning: Applies to wled00/**/*.{cpp,h,hpp,c} usermods/**/*.{cpp,h,hpp,c} : Wrap platform-conditional C++ includes in `#ifdef ARDUINO_ARCH_ESP32` / `#ifdef ESP8266`

Learnt from: CR
Repo: MoonModules/WLED-MM PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-04-14T23:40:02.031Z
Learning: Applies to wled00/**/*.{cpp,h,hpp,c} usermods/**/*.{cpp,h,hpp,c} : Prefer `constexpr` over `#define` for compile-time constants in C++

Learnt from: CR
Repo: MoonModules/WLED-MM PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-04-14T23:40:02.031Z
Learning: Applies to wled00/**/*.{cpp,h,hpp,c} usermods/**/*.{cpp,h,hpp,c} : Avoid `String` in hot paths in C++; acceptable in config/setup code

Learnt from: CR
Repo: MoonModules/WLED-MM PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-04-14T23:40:02.031Z
Learning: Applies to wled00/**/*.{cpp,h,hpp,c} usermods/**/*.{cpp,h,hpp,c} : Use `static_assert` over `#if ... `#error`` in C++ for compile-time validation

Learnt from: CR
Repo: MoonModules/WLED-MM PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2026-04-14T23:39:33.590Z
Learning: Applies to wled00/**/*.{h,hpp,cpp} : Every `WLED_DISABLE_*` flag must exactly match one of: `2D`, `ADALIGHT`, `ALEXA`, `BROWNOUT_DET`, `ESPNOW`, `FILESYSTEM`, `HUESYNC`, `IMPROV_WIFISCAN`, `INFRARED`, `LOXONE`, `MQTT`, `OTA`, `PARTICLESYSTEM1D`, `PARTICLESYSTEM2D`, `PIXELFORGE`, `WEBSOCKETS` — misspellings are silently ignored by the preprocessor

Learnt from: CR
Repo: MoonModules/WLED-MM PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-04-14T23:40:02.031Z
Learning: Applies to wled00/**/*.{cpp,h,hpp,c} usermods/**/*.{cpp,h,hpp,c} : Verify feature-flag spelling exactly (misspellings are silently ignored by preprocessor)

Learnt from: CR
Repo: MoonModules/WLED-MM PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2026-04-14T23:39:33.590Z
Learning: Applies to wled00/**/*.{h,hpp,cpp} : When a larger block of code is generated by an AI tool, embed it into `// AI: below section was generated by an AI` ... `// AI: end` comments

Learnt from: CR
Repo: MoonModules/WLED-MM PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2026-04-14T23:39:33.590Z
Learning: Applies to wled00/**/*.{h,hpp,cpp} : AI-generated code must be well documented with meaningful comments explaining intent, assumptions, and non-obvious logic — explain concepts and reasoning rather than rephrasing source code

Learnt from: CR
Repo: MoonModules/WLED-MM PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-04-14T23:40:02.031Z
Learning: Applies to wled00/**/*.{cpp,h,hpp,c} usermods/**/*.{cpp,h,hpp,c} : Mark AI-generated C++ code blocks with `// AI: below section was generated by an AI` / `// AI: end` comments

Learnt from: CR
Repo: MoonModules/WLED-MM PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2026-04-14T23:39:33.590Z
Learning: Applies to wled00/**/*.{h,hpp,cpp} : Every non-trivial AI-generated function must have a brief comment describing what it does, with parameter explanations when names alone are not self-explanatory

Learnt from: CR
Repo: MoonModules/WLED-MM PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-04-14T23:40:02.031Z
Learning: Applies to wled00/**/*.{cpp,h,hpp,c} usermods/**/*.{cpp,h,hpp,c} : Use `//` for inline C++ comments (with space after) and `/* */` for block comments

Learnt from: CR
Repo: MoonModules/WLED-MM PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2026-04-14T23:39:33.590Z
Learning: Applies to wled00/**/*.{h,hpp,cpp} : Unused or dead code must be justified or removed to keep the codebase clean, maintainable, and readable

Learnt from: CR
Repo: MoonModules/WLED-MM PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-04-14T23:40:02.031Z
Learning: Changes to `platformio.ini` require maintainer approval

Learnt from: CR
Repo: MoonModules/WLED-MM PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2026-04-14T23:39:33.590Z
Learning: Applies to platformio.ini : Modifications to `platformio.ini` must be approved explicitly by a maintainer or WLED organisation Member — modifications to the global build environment may break GitHub Actions builds

Learnt from: softhack007
Repo: MoonModules/WLED-MM PR: 343
File: platformio_override.ini.olaf.example:6-8
Timestamp: 2026-04-05T13:58:42.281Z
Learning: In MoonModules/WLED-MM, new PlatformIO build environment examples must NOT be added as separate `.ini` or `.ini.example` files. They must be placed as commented-out named sections (e.g., `;[env:some_name]`) inside `platformio_override.ini.sample`. The generic `[env]` block (which applies globally to all environments) must not be used directly in examples. This convention is enforced by maintainer softhack007.

Learnt from: softhack007
Repo: MoonModules/WLED-MM PR: 343
File: platformio_override.ini.olaf.example:6-8
Timestamp: 2026-04-05T16:19:06.776Z
Learning: In MoonModules/WLED-MM, the correct way to activate a custom data_dir (e.g., `data_dir = ${PROJECT_DIR}/fs_data`) in a local build is to add that directive inside a properly extended named environment in the user's local `platformio_override.ini`. This usage should be documented in the relevant README.md rather than provided as a standalone `.ini` or `.ini.example` template file. No example override file should be committed to the repository for this purpose.

Learnt from: softhack007
Repo: MoonModules/WLED-MM PR: 270
File: usermods/usermod_v2_rotary_encoder_ui_ALT/usermod_v2_rotary_encoder_ui_ALT.h:155-157
Timestamp: 2025-10-22T21:50:25.839Z
Learning: In WLED-MM PR `#270`, only Effect (Mode) IDs are migrated to 16-bit; Palette IDs and counts remain 8-bit. Usermod code should widen mode-related indices/loops to uint16_t while keeping palette-related indices/loops as uint8_t.

@softhack007

This comment was marked as outdated.

@coderabbitai

This comment was marked as outdated.

@softhack007

Copy link
Copy Markdown
Collaborator

Nitpick comments (1)

usermods/INA219_v2/usermod_ina219.h > 80-83: ⚡ Quick win

Release INA219 state when the usermod is disabled.
This early return leaves ina219 allocated and sensorFound stale while disabled. Clearing them here keeps state consistent and frees RAM.

♻️ Suggested patch

   void setup() override {
     if (!enabled) {
+      if (ina219) {
+        delete ina219;
+        ina219 = nullptr;
 +      }
+      sensorFound = false;
       initDone = true;  // mark as initialized so re-enabling via UI triggers (re)setup
       return;
     }

@Topchris18 please check if this recommendation makes sense.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants